<template>
	<view>
		<view>
			<uni-nav-bar shadow left-icon="left" dark title="合同详细" @clickLeft="back()" />
		</view>
		
		<view>
			<uni-card>
			<uni-row>
				<text style="font-weight: 600;">合同编号:</text>{{from.contractNum}}
			</uni-row>
			<uni-row>
				<text style="font-weight: 600;">合同名称:</text>{{from.contractName}}
			</uni-row>
		    <uni-row>
			    <text style="font-weight: 600;">合同类型:</text>{{from.contractType}}
			</uni-row>
			<uni-row>
			    <text style="font-weight: 600;">合同模版:</text>{{from.templateName}}
			</uni-row>
			
			<uni-row><text style="font-weight: 600;">公司名称:</text>{{from.companyName}}</uni-row>
		   
			<uni-row><text style="font-weight: 600;">供应商名称:</text>{{from.supplierName}}</uni-row>
			
			<uni-row><text style="font-weight: 600;">付款方式:</text>{{from.paymentMethod}}</uni-row>
		
			<view  v-if="from.contractStatus==0"><text style="font-weight: 600;">合同状态:</text><text>未提交</text></view>
			<view  v-if="from.contractStatus==1"><text style="font-weight: 600;">合同状态:</text><text >已提交</text></view>
			<view  v-if="from.contractStatus==2"><text style="font-weight: 600;">合同状态:</text><text>已通过</text></view>
			<view  v-if="from.contractStatus==3"><text style="font-weight: 600;">合同状态:</text><text>已驳回</text></view>
			<uni-row><text style="font-weight: 600;">合同有效期:</text>{{from.contractSigningDate}}到{{from.contractExpirationDate}}</uni-row>
			<uni-row><text style="font-weight: 600;">发票类型:</text>{{from.invoiceType}}</uni-row>
			<uni-row><text style="font-weight: 600;">合同总金额:</text>{{from.totalContractAmount}}(元)</uni-row>
			<uni-row><text style="font-weight: 600;">合同总金额(大写):</text>{{from.totalContractAmountInWords}}</uni-row>
			<view>
				<uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#ffaa00" @clickItem="onClickItem" style="background-color: #fff"  />
			</view>
			<view>
				<view v-if="current === 0">
				<uni-row><text style="font-weight: 600;">合同条款第一条:</text><uni-easyinput type="textarea" v-model="from.contractItem1"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第二条:</text><uni-easyinput type="textarea" v-model="from.contractItem2"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第三条:</text><uni-easyinput type="textarea" v-model="from.contractItem3"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第四条:</text><uni-easyinput type="textarea" v-model="from.contractItem4"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第五条:</text><uni-easyinput type="textarea" v-model="from.contractItem5"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">其他条款:</text><uni-easyinput type="textarea" v-model="from.otherTerms"></uni-easyinput></uni-row>
				<uni-row>
					<text style="font-weight: 600;">验收标准:</text>
				<uni-easyinput type="textarea" v-model="from.acceptanceStandard"></uni-easyinput>
				</uni-row>
				<uni-row>
					<text style="font-weight: 600;">违约责任:</text>
					<uni-easyinput type="textarea" v-model="from.breachOfContract"></uni-easyinput>
				</uni-row>
				<uni-row>
					<text style="font-weight: 600;">合同备注:</text>
					<uni-easyinput type="textarea" v-model="from.contractRemarks"></uni-easyinput>
				</uni-row>
				</view>
				<view v-if="current === 1">
					<uni-table border stripe >
						<uni-tr>
					<uni-th align="center">物料名称</uni-th>
					<uni-th align="center">物料型号</uni-th>
					<uni-th align="center">数量</uni-th>
					<uni-th align="center">单位</uni-th>
					<uni-th align="center">单价</uni-th>
					<uni-th align="center">总价</uni-th>
						</uni-tr>
						<uni-tr v-for="(item,index) in tables" :key="index">
							<uni-td align="center">{{item.materialName}}</uni-td>
							<uni-td align="center">{{item.materialModel}}</uni-td>
							<uni-td align="center">{{item.quantity}}</uni-td>
							<uni-td align="center">{{item.unit}}</uni-td>
							<uni-td align="center">{{item.unitPrice}}</uni-td>
							<uni-td align="center">{{item.totalPrice}}</uni-td>
						</uni-tr>

					</uni-table>
				</view>
			
				<view v-if="current === 2">
					<view style="text-align: center;height:700rpx;;">					
		           <web-view :src="saveUrl"></web-view>				    </view>
				</view>
			</view>
			</uni-card>
		</view>
		
		
	</view>
</template>

<script>
	import {materialInventoryTable,DocumentFormDatatable} from "@/api/system/user"
	export default {
		data() {
			return {
				saveUrl:null,
				from:null,
				current:0,
				tables:null,
				items: ['合同条款','采购明细','附件'],		
			}
		},
		onLoad() {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', (data) => {
			  this.from = data.data
			})
			this.get()
			
		},
		methods: {
			get(){
			
			materialInventoryTable(this.from.rowId).then(res=>{
				this.tables=res.rows
			})
				
			this.docLabel='contractFile'
			DocumentFormDatatable(this.from.contractNum,this.docLabel).then(res=>{
			
			this.saveUrl='http://39.103.203.89:7072/temp/cgscrm/doc'+res.rows[0].saveUrl
		
			})		
				
			},
			back(){
					this.$tab.reLaunch('/pages/work/purchaser/contract')
			},
			onClickItem(e) {
						if (this.current !== e.currentIndex) {
							this.current = e.currentIndex
						}
					},
		}
	}
</script>

<style>

</style>
